<!DOCTYPE html>
<html>
<head>
    <meta charset='UTF-8'>
    <title>生命周期</title>
    <script src="../js/vue.js"></script>
</head>
<body>
    <div id="root">
        <h2 :style="{opacity:opacity}">富士山下</h2>
        <button @click="opacity=1">重置</button>
        <button @click="stop">点击停止变换</button>
    </div>
</body>
<!--   JS   -->
    <script>
        const vm = new Vue({
            el:'#root',
            data:{
                opacity:1
            },
            methods: {
                stop(){
                    // clearInterval(this.timer)
                    this.$destroy()
                }
            },
            //Vue完成模板的解析并把真实的DOM放入页面后调用
            mounted() {
                console.log('mounted',this)
                this.timer = setInterval(() =>{
                    this.opacity -=0.01
                    if(this.opacity <=0) this.opacity=1
                },16)
            },
            beforeDestroy() {
                console.log('vm要销毁了')
                clearInterval(this.timer)
            },
        })
    </script>
</html>